package com.aceitunaproject.server.initializer;

import com.aceitunaproject.server.AceitunaContext;
import com.aceitunaproject.server.ServerConfiguration;
import com.aceitunaproject.server.map.MapManager;
import com.aceitunaproject.server.map.MapTile;
import com.aceitunaproject.server.map.MapType;
import com.aceitunaproject.server.terrain.TerrainTypeLoader;

/**
 * @author Federico Bergstein
 * 
 * 
 *         A simple initializer for testing purposes
 * 
 */
public class SquareMapTestInitializer implements Initializer {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.aceitunaproject.server.initializer.Initializer#Initialize()
	 */
	@Override
	public boolean Initialize() {

		TerrainTypeLoader ttLoader = ServerConfiguration.getTerrainTypeLoader();
		MapManager mapManager = AceitunaContext.getMapManager();
		// creates the test world map
	    mapManager.setMapType(MapType.RectangularTiles);
		mapManager.createWorldMap(7, 15);

		for (MapTile tile : mapManager.getAllTiles()) {

			if (tile.getXPos() != 4 && tile.getYPos() != 4) {

				tile.AddTerrainType(ttLoader.getTerrainTypes().get(
								"Grassland"));
			}
			else
			{
				tile.AddTerrainType(ttLoader.getTerrainTypes().get(
				"Plains"));
			}
				
			
		}

		// TODO: create outside the map manager,
		// currently impossible because initializer can not create managed
		// references, the map manager should have a method that returns map
		// tiles
		// already created in the object store

		// start the ticking.
		AceitunaContext.getTickManager().startTickTask();

		return true;
	}

}
